<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备名称" prop="equipmentName">
        <el-input
          v-model="queryParams.equipmentName"
          placeholder="请输入设备名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安装单位" prop="installationUnit">
        <el-input
          v-model="queryParams.installationUnit"
          placeholder="请输入安装单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:nmEquipment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:nmEquipment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:nmEquipment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleQrcode"
          v-hasPermi="['system:nmEquipment:qrcode']"
        >生产二维码</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:nmEquipment:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="nmEquipmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="设备所属车间" align="center" prop="equipmentWorkshop" />
      <el-table-column label="设备位号" align="center" prop="equipmentNo" />
      <el-table-column label="出厂日期" align="center" prop="productionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数量" align="center" prop="num" />
      <el-table-column label="设备名称" align="center" prop="equipmentName" />
      <el-table-column label="安装单位" align="center" prop="installationUnit" />
      <el-table-column label="出厂编号" align="center" prop="productionNo" />
      <el-table-column label="型号" align="center" prop="model" />
     
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:nmEquipment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:nmEquipment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改设备信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <h4>设备简要信息</h4>
        <el-row>
          <el-col :span="8">
            <el-form-item label="设备所属车间" prop="equipmentWorkshop">
              <el-input v-model="form.equipmentWorkshop" placeholder="请输入设备所属车间" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备照片">
              <imageUpload  v-model="form.equipmentImg"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备简介" prop="equipmentRenark">
              <el-input v-model="form.equipmentRenark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

        <h4>设备主要技术参数</h4>
        <el-row>
          <el-col :span="8">
             <el-form-item label="设备位号" prop="equipmentNo">
              <el-input v-model="form.equipmentNo" placeholder="请输入设备位号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出厂日期" prop="productionDate">
              <el-date-picker clearable size="small"
                v-model="form.productionDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择出厂日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
             <el-form-item label="数量" prop="num">
              <el-input v-model="form.num" placeholder="请输入数量" />
            </el-form-item>
          </el-col>
        </el-row>
        
       <el-row>
          
          <el-col :span="8">
            <el-form-item label="设备名称" prop="equipmentName">
          <el-input v-model="form.equipmentName" placeholder="请输入设备名称" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="安装单位" prop="installationUnit">
              <el-input v-model="form.installationUnit" placeholder="请输入安装单位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出厂编号" prop="productionNo">
              <el-input v-model="form.productionNo" placeholder="请输入出厂编号" />
            </el-form-item>
          </el-col>
        </el-row>
 
        
        <el-row>
          <el-col :span="8">
            <el-form-item label="型号" prop="model">
          <el-input v-model="form.model" placeholder="请输入型号" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="外形尺寸" prop="overallDimension">
          <el-input v-model="form.overallDimension" placeholder="请输入外形尺寸" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="总重(kg)" prop="totalWeight">
          <el-input v-model="form.totalWeight" placeholder="请输入总重(kg)" />
        </el-form-item>
          </el-col>
        </el-row>
        
        <el-row>  
          <el-col :span="8">
            <el-form-item label="最大起吊重量(kg)" prop="liftingWeightMax">
          <el-input v-model="form.liftingWeightMax" placeholder="请输入最大起吊重量(kg)" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="制造厂" prop="manufacturer">
          <el-input v-model="form.manufacturer" placeholder="请输入制造厂" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="投产日期" prop="productionTime">
              <el-date-picker clearable size="small"
                v-model="form.productionTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择投产日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <h4>操作条件及性能</h4>
        <el-row>
          <el-col :span="8">
            <el-form-item label="介质" prop="medium">
          <el-input v-model="form.medium" placeholder="请输入介质" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设计流量(m3/h)" prop="designFlow">
          <el-input v-model="form.designFlow" placeholder="请输入设计流量(m3/h)" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备转速" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入设备转速" />
        </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          
          <el-col :span="8">
            <el-form-item label="入口温度(℃)" prop="inletTemperature">
          <el-input v-model="form.inletTemperature" placeholder="请输入入口温度(℃)" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="正常流量" prop="normalFlow">
          <el-input v-model="form.normalFlow" placeholder="请输入正常流量" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="轴功率" prop="shaftPower">
          <el-input v-model="form.shaftPower" placeholder="请输入轴功率" />
        </el-form-item>
          </el-col>
        </el-row>
        
    
        
        <el-row>
          <el-col :span="8">
            <el-form-item label="粘度" prop="viscosity">
          <el-input v-model="form.viscosity" placeholder="请输入粘度" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入口压力(MPa)" prop="inletPressure">
          <el-input v-model="form.inletPressure" placeholder="请输入入口压力(MPa)" />
        </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="气蚀余量(m)" prop="cavitationAllowance">
          <el-input v-model="form.cavitationAllowance" placeholder="请输入气蚀余量(m)" />
        </el-form-item>
          </el-col>
        </el-row>
        
        <el-row>
         
          <el-col :span="8">
            <el-form-item label="扬程(m)" prop="lift">
          <el-input v-model="form.lift" placeholder="请输入扬程(m)" />
        </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="出口压力(MPa)" prop="outletPressure">
          <el-input v-model="form.outletPressure" placeholder="请输入出口压力(MPa)" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="吸入温度下密度" prop="suctionTemperature">
          <el-input v-model="form.suctionTemperature" placeholder="请输入吸入温度下密度" />
        </el-form-item>
          </el-col>
        </el-row>

        
        <h4>驱动装置数据</h4>
        
        <el-row>
          <el-col :span="8">
            <el-form-item label="驱动机" prop="driving">
          <el-input v-model="form.driving" placeholder="请输入驱动机" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="驱动转速" prop="drivingSpeed">
          <el-input v-model="form.drivingSpeed" placeholder="请输入驱动转速" />
        </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="防爆等级" prop="explosionProofGrade">
          <el-input v-model="form.explosionProofGrade" placeholder="请输入防爆等级" />
        </el-form-item>
          </el-col>
        </el-row>

        <el-row>
         
          <el-col :span="8">
            <el-form-item label="驱动机型号" prop="drivingMachine">
          <el-input v-model="form.drivingMachine" placeholder="请输入驱动机型号" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="驱动机出厂日期" prop="drivingProductionDate">
          <el-date-picker clearable size="small"
            v-model="form.drivingProductionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择驱动机出厂日期">
          </el-date-picker>
        </el-form-item>
          </el-col>
          <el-col :span="8">
             <el-form-item label="驱动机制造厂" prop="drivingManufacturer">
          <el-input v-model="form.drivingManufacturer" placeholder="请输入驱动机制造厂" />
        </el-form-item>
          </el-col>
        </el-row>


       
        <h4>设备正常运行参数</h4>
        <el-form-item label="" prop="equipmentOperationParameters">
          <el-input v-model="form.equipmentOperationParameters" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <h4>设备维修维护内容及周期</h4>
        <el-row>
          <el-col :span="8">
             <el-form-item label="中修检修周期" prop="intermediateMaintenanceCycle">
          <el-input v-model="form.intermediateMaintenanceCycle" placeholder="请输入中修检修周期" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="大修检修周期" prop="overhaulCycle">
          <el-input v-model="form.overhaulCycle" placeholder="请输入大修检修周期" />
        </el-form-item>
          </el-col>
        </el-row>
       
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNmEquipment, getNmEquipment, delNmEquipment, addNmEquipment, updateNmEquipment, exportNmEquipment,handleQrcode } from "@/api/jetLinks/nmEquipment";
import ImageUpload from '@/components/ImageUpload';


export default {
  name: "NmEquipment",
  components: {
    ImageUpload,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备信息管理表格数据
      nmEquipmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipmentWorkshop: null,
        equipmentImg: null,
        equipmentRenark: null,
        equipmentNo: null,
        productionDate: null,
        num: null,
        equipmentName: null,
        installationUnit: null,
        productionNo: null,
        model: null,
        overallDimension: null,
        totalWeight: null,
        liftingWeightMax: null,
        manufacturer: null,
        productionTime: null,
        medium: null,
        designFlow: null,
        speed: null,
        inletTemperature: null,
        normalFlow: null,
        shaftPower: null,
        viscosity: null,
        inletPressure: null,
        cavitationAllowance: null,
        lift: null,
        outletPressure: null,
        suctionTemperature: null,
        driving: null,
        drivingSpeed: null,
        explosionProofGrade: null,
        drivingMachine: null,
        drivingProductionDate: null,
        drivingManufacturer: null,
        equipmentOperationParameters: null,
        intermediateMaintenanceCycle: null,
        overhaulCycle: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备信息管理列表 */
    getList() {
      this.loading = true;
      listNmEquipment(this.queryParams).then(response => {
        this.nmEquipmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        equipmentWorkshop: null,
        equipmentImg: null,
        equipmentRenark: null,
        equipmentNo: null,
        productionDate: null,
        num: null,
        equipmentName: null,
        installationUnit: null,
        productionNo: null,
        model: null,
        overallDimension: null,
        totalWeight: null,
        liftingWeightMax: null,
        manufacturer: null,
        productionTime: null,
        medium: null,
        designFlow: null,
        speed: null,
        inletTemperature: null,
        normalFlow: null,
        shaftPower: null,
        viscosity: null,
        inletPressure: null,
        cavitationAllowance: null,
        lift: null,
        outletPressure: null,
        suctionTemperature: null,
        driving: null,
        drivingSpeed: null,
        explosionProofGrade: null,
        drivingMachine: null,
        drivingProductionDate: null,
        drivingManufacturer: null,
        equipmentOperationParameters: null,
        intermediateMaintenanceCycle: null,
        overhaulCycle: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNmEquipment(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNmEquipment(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNmEquipment(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除设备信息管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delNmEquipment(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 生产二维码 */
    handleQrcode(row) {
      this.loading = true;
      const ids = row.id || this.ids;
      handleQrcode(ids).then(response => {
        this.msgSuccess("生产成功");
        this.getList();
        this.loading = false;
      });
        
    },

    
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有设备信息管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportNmEquipment(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
